unit oAgentTourniquet;

interface

uses
  uOSPABA;

type
  TAssitantTournquet = class(tProcess)
    public
      procedure ProcessMessage(var paMessage: tMessageForm); override;
  end;

  TAgentTourniquet = class(tAgent)
    strict private
      aAssistantTourniquet: TAssitantTournquet;
    public
      property AssistantTourniquet: TAssitantTournquet read aAssistantTourniquet;
      constructor create(paID: Cardinal; paSim: TSimulation; paParent:TAgent);
  end;

  TManagerTourniquet = class(tManager)
    public
      procedure ProcessMessage(var paMessage: TMessageForm); override;
  end;

implementation

uses
  oSimulation, oTurniquet;

{ TManagerTourniquet }

procedure TManagerTourniquet.ProcessMessage(var paMessage: TMessageForm);
begin

  case paMessage.Code of

    mcPrejstTurniket:
    begin
      paMessage.Addressee := (MyAgent as TAgentTourniquet).AssistantTourniquet;
      StartContinualAssistant(paMessage);
    end;

    mcFinish:
    begin
      paMessage.Code := mcObsluzeny;
      Response(paMessage);
    end;

  end;

end;

{ TAgentTourniquet }

constructor TAgentTourniquet.create(paID: Cardinal; paSim: TSimulation;
  paParent: TAgent);
begin
  inherited create(paID,paSim,paParent);
  TManagerTourniquet.create(IDManazerTurniketov,self,NoMOPN);
  aAssistantTourniquet := TAssitantTournquet.Create(IDAsistentTuniketov,self,NoMOPN);
  AddOwnMessage(mcPrejstTurniket);
end;

{ TAssitantTournquet }

procedure TAssitantTournquet.ProcessMessage(var paMessage: tMessageForm);
begin

  case paMessage.Code of

    mcStart:
    begin
      paMessage.Code := mcPresielTurniket;
      Hold(((paMessage as TPSMessage).Actor.Target as TTurniquet).Generator.Rand,paMessage);
    end;

    mcPresielTurniket:
    begin
      AssistantFinished(paMessage);
    end;

  end;

end;

end.
